package com.xc.h05.controller.wutao;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Privatemessage;
import com.xc.h05.service.wutao.PrivatemessageService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Privatemessage")
public class PrivatemessageController {
    @Autowired
    private PrivatemessageService privatemessageService;
    @GetMapping("/findAll")
    public List<Privatemessage> findAll(){
        return privatemessageService.findAll();
    }

    @PostMapping("/add")
    public R add(@RequestBody Privatemessage privatemessage) {
        int add = privatemessageService.add(privatemessage);
        if (add != 0) {
            return R.ok(privatemessage);
        } else {
            return R.fail("添加失败");
        }
    }
    @DeleteMapping("/delete")
    public int delete(Long id){
        return privatemessageService.delete(id);
    }

    @PutMapping("/update")
    public int update(@RequestBody Privatemessage privatemessage){
        return privatemessageService.update(privatemessage);
    }

    //    分页查询所有
    @GetMapping("/getAll")
    public R getAll(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
            Privatemessage privatemessage
    ) {
        PageInfo<Privatemessage> pageInfo = privatemessageService.findByPage(pageNum, pageSize,privatemessage);
        return R.ok(pageInfo);
    }
    //    根据id批量删除
    @PostMapping("/deleteByIds")
    public R deletelevelByIds(@RequestBody java.util.List<Long> ids2) {
        int i = privatemessageService.deleteByIds(ids2);
        if (i >= 0) {
            return R.ok("批量删除成功");
        }else return R.fail ("批量删除失败");
    }
    //根据咨询师id查询
    @GetMapping("/findByCid")
    public List<Privatemessage> findByCid(Integer cid){
        return privatemessageService.findByCid(cid);
    }
}